package top.resty.erp.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import top.resty.erp.domain.User;
import top.resty.erp.service.UserService;

import java.util.List;

/**
 * <pre>
 *
 * </pre>
 *
 * @author : resty
 * @date : 2021年04月01 18:12
 */
@Controller
@RequestMapping("/user")
public class UserController {
	
	@Autowired
	private UserService userService;
	
	@RequestMapping("saveUser")
	@ResponseBody
	public Integer getUserId(User user ){
		Integer id = 0 ;
		List<User> users = userService.findUsersByCondition(user);
		
		if(users.size()>0){
			id = users.get(0).getId();
		}else{
			userService.savetUser(user);
			id = user.getId();
		}
		return id;
	}
	
}
